﻿using Furion;
using HiSportApplet.Core.Enum;
using HiSportApplet.Core.Options;
using Microsoft.Extensions.DependencyInjection;
using NewLife.Caching;
using SqlSugar;

namespace HiSportApplet.Core.Cache
{
    public static class CacheSetup
    {
        /// <summary>
        /// 缓存注册（新生命Redis组件）
        /// </summary>
        /// <param name="services"></param>
        public static void AddCache(this IServiceCollection services)
        {
          

            ICache cache = NewLife.Caching.Cache.Default;

            var cacheOptions = App.GetOptions<CacheOptions>();
            if (cacheOptions.CacheType == CacheTypeEnum.Redis.ToString())
            {
                cache = new FullRedis(new RedisOptions
                {
                    Configuration = cacheOptions.Redis.Configuration,
                    Prefix = cacheOptions.Redis.Prefix
                });
            }
            services.AddSingleton(cache);
        }
    }
}
